<%= form_for [:admin, @variant], :url => @variant.new_record? ? admin_product_variants_path(:product_id => params[:product_id]) : admin_product_variant_path(:product_id => params[:product_id], :id => params[:id]), :validate => true do |f| %>

  <%= render "shared/error_messages", :target => @variant %>

  <h2><%= @variant.new_record? ? "Nová varianta" : @variant.is_master? ? "Editace hlavní varianty č. \"#{@variant.number}\"" : "Editace varianty č. \"#{@variant.number}\"" %></h2>

  <table>
    <tbody>
      <tr>
        <th><%= f.label :number %></th>
        <td><%= f.text_field :number, :maxlength => 30, :size => 20 %></td>
      </tr>
      <tr>
        <th><%= f.label :price %></th>
        <td><%= f.text_field :price, :maxlength => 15, :size => 5, :onfocus => "if(this.value == 0.00) this.value='';" %>&nbsp;Kč</td>
      </tr>
      <tr>
        <th><%= f.label :state %></th>
        <td><%= f.select :state, {"#{t 'enumerations.variant.state.on_sale'}" => "on_sale", "#{t 'enumerations.variant.state.not_on_sale'}" => "not_on_sale", "#{t 'enumerations.variant.state.hidden'}" => "hidden"} %></td>
      </tr>
    </tbody>
  </table>

  <% unless @product.parameters.blank? %>
    <table>
      <tbody>
        <tr>
          <% @product.parameters.each_with_index do |parameter, index| %>
            <td <%= "colspan='3'" if @product.parameters.length == 1 %>
                <%= "colspan='2'" if @product.parameters.length == 2 && index == 1 %>>
                <em><%= parameter.name.capitalize %></em>
            </td>
          <% end %>
        </tr>
        <tr>
          <% @product.parameters.each do |parameter| %>
            <td <%= "colspan='3'" if @product.parameters.length == 1 %> style="padding-left: 5px;">
              <%= select_tag "variant[parameter_value_ids][]", options_from_collection_for_select(parameter.parameter_values.collect, :id, :value, @variant.parameter_values.collect {|pv| pv.parameter == parameter ? pv.id : ""}), {:include_blank => true, :size => "10", :style => "width: 90px; height: 100%;"} %>
            </td>
          <% end %>
        </tr>
        <tr>
          <td colspan="10"><%= f.submit %></td>
        </tr>
      </tbody>
    </table>
  <% else %>
    <p>K tomuto výrobku nebyly zatím přiřazeny žádné volitelné parametry. <%= link_to "Přiřadit volitelný parametr.", admin_product_product_parameters_path(:product_id => @product.id) %></p>
  <% end %>
<% end %>